<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/22
 * Time: 10:11
 */
namespace app\admin\model\project;
use app\admin\model\copy\CopyConfig;

class MyProject
{
    /**
     * @param $data
     * @return bool|int
     */
    public static function create($data){
        if(!is_dir('../app/'.$data['dir'].'/config')){
            chmod('../app',0777);
            mkdir('../app/'.$data['dir'].'/config',0777,true);
        }
        return CopyConfig::changeConfig($data,'../app/'.$data['dir'].'/config/project.php');
    }
    /**获取目前有的模块
     * @param string|null $path
     * @param array $array
     * @return array
     */
    static public function getDirList(string $path=null,array $array=['admin']){
        if(!$path){
            $path = '../app';
        }
        $dir =scandir($path);
        $data = [];
        foreach ($dir as $value){
            if($value!=='.'&&$value!=='..'){
                if(is_dir(rtrim($path,'/').'/'.$value)){
                    if(!in_array($value,$array)){
                        $ar = include '../app/'.$value.'/config/project.php';
                        $data[] = $ar;
                    }
                }
            }
        }
        return $data;
    }
}